//
//  CellODBottom.m
//  LCExpress
//
//  Created by mac1 on 15/10/23.
//  Copyright © 2015年 D0. All rights reserved.
//

#import "CellODBottom.h"

#import "VCHandler.h"

#import "VCReceipt.h"

#import "VCRoute.h"

@interface CellODBottom ()


@property (nonatomic, strong) ZTButton * btnPreviousSelected;

@property (nonatomic, strong) UIViewController * vcMain;

@property (nonatomic, strong) UIViewController * vcPrevious;

@property (nonatomic, strong) VCHandler * vcHandler;

@property (nonatomic, strong) VCReceipt * vcReceipt;

@property (nonatomic, strong) VCRoute * vcRoute;


@end

@implementation CellODBottom

- (void)awakeFromNib {
    // Initialization code
}


-(CellODBottom*)initWithVC:(UIViewController*)vc
{
    self = [super init];
    if(self)
    {
        [self addBtn];
        
        self.vcMain = vc;
    }
    return self;
}


-(void)addBtn
{
    
    NSArray * arrBtnTitle = @[@"路由信息", @"  经手人", @"签收底单"];
    
    NSArray * arrBtnImg = @[@"icon_Path", @"icon_Handler", @"icon_Sign"];
    
    for(int i = 0; i < 3; i++)
    {

        ZTButton * btn = [ZTButton buttonWithType:UIButtonTypeCustom];
        
        [self.contentView addSubview:btn];
        
        btn.frame = CGRectMake(SCREEN_WIDTH/3*i,  0,  SCREEN_WIDTH/3, 40);
        
        btn.backgroundColor = HEX2RGBA(0x02935f, 1.0);

        [btn setTitle:arrBtnTitle[i] forState:UIControlStateNormal];
        
        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        btn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        [btn setTitleEdgeInsets:UIEdgeInsetsMake(20, -20, 0, 0)];

        [btn setImage:[UIImage imageNamed:arrBtnImg[i]] forState:UIControlStateNormal];
        
        [btn setImageEdgeInsets:UIEdgeInsetsMake(-10, 53, 0, 0)];
        
        [btn setAction:^(ZTButton * btn) {

            btn.tag = 1200+i;
            
            btn.selected = YES;

            self.btnPreviousSelected.selected = NO;

            self.btnPreviousSelected.backgroundColor = RGBA(2, 147, 95, 1);

            switch (btn.tag - 1200)
            {
                case 0:
                    
                    [self showRouteInfo];
                    
                    break;
                    
                case 1:
                    
                    [self showHandler];
                    
                    break;
                    
                case 2:
                    
                    [self showReceipt];
                    
                    break;
                    
                default:
                    
                    break;
            }

            btn.backgroundColor = RGBA(0, 130, 80, 1);

            self.btnPreviousSelected = btn;
            
        }];
        
        //第一次运行时,显示第一个页面和第一个按钮,将这个按钮点击一下
        if(i == 0)
        {
            if(btn.action)
                btn.action(btn);
        }
        
    }
}



///// 显示路由信息
-(void)showRouteInfo
{

    [self.vcPrevious.view removeFromSuperview];
    
    [self.vcPrevious removeFromParentViewController];

    self.vcRoute = [[VCRoute alloc]init];
    
    self.vcRoute.view.frame = CGRectMake(0, 40,  SCREEN_WIDTH, SCREEN_HEIGHT);
    
    [self.vcMain addChildViewController:self.vcRoute];

    //将 路由信息 的视图加入到当前视图的子视图中，以显示出来
    [self.contentView addSubview:self.vcRoute.view];
    
    self.vcPrevious = self.vcRoute;

}


////!@brief 显示经手人
-(void)showHandler
{
    
    [self.vcPrevious.view removeFromSuperview];
    
    [self.vcPrevious removeFromParentViewController];
    
    self.vcHandler = [[VCHandler alloc]init];
    
    self.vcHandler.view.frame = CGRectMake(0, 40, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    [self.vcMain addChildViewController:self.vcHandler];
    
    [self.contentView addSubview:self.vcHandler.view];
    
}


/////显示底单
-(void)showReceipt
{

    [self.vcPrevious.view removeFromSuperview];

    [self.vcPrevious removeFromParentViewController];

    self.vcReceipt = [[VCReceipt alloc]init];

    self.vcReceipt.view.frame = CGRectMake(0, 40, SCREEN_WIDTH, SCREEN_HEIGHT);

    [self.vcMain addChildViewController:self.vcReceipt];

    [self.contentView addSubview:self.vcReceipt.view];

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
